#!/bin/bash

LOCAL_PATH=$1
REMOTE_PATH=$2

declare -A remote_info=(
    ["1"]="csst 192.168.20.22 123"
    ["2"]="root 10.10.100.1 123"
    ["3"]="lighthouse 111.229.30.135"
)

declare -A home_paths=(
    ["1"]="/home/csst"
    ["2"]="/home/root"
    ["3"]="/application"
)

echo "请选择远程主机："
for key in "${!remote_info[@]}"; do
    echo "$key) ${remote_info[$key]}"
done

read -p "请输入选项编号（1/2/3）： " choice

if [[ -n $choice && $choice =~ ^[1-3]$ ]]; then
    IFS=' ' read -r REMOTE_USER REMOTE_HOST PASSWORD <<< "${remote_info[$choice]}"
    echo "您选择了：用户 $REMOTE_USER，主机 $REMOTE_HOST，密码 $PASSWORD"
    
    # 检查REMOTE_PATH是否为~
    if [[ "$REMOTE_PATH" == "~" ]]; then
        REMOTE_PATH=${home_paths[$choice]}
        echo "REMOTE_PATH已设置为：$REMOTE_PATH"
    fi
else
    echo "无效的选择，请重新运行脚本并输入正确的编号！"
    exit 1
fi

sshpass -p "$PASSWORD" scp "$LOCAL_PATH" "$REMOTE_USER"@"$REMOTE_HOST":"$REMOTE_PATH"